home *** CD-ROM | disk | FTP | other *** search
/ Treccani Italiana Di Scienze Lettere Ed Arti / [Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso / pc / data / xxi_appendice_dvd.swf / scripts / __Packages / mx / controls / NumericStepper.as < prev    next >
Text File  |  2007-11-08  |  11KB  |  376 lines

  1. class mx.controls.NumericStepper extends mx.core.UIComponent
  2. {
  3.    static var symbolName = "NumericStepper";
  4.    static var symbolOwner = mx.controls.NumericStepper;
  5.    static var version = "2.0.2.126";
  6.    var className = "NumericStepper";
  7.    var upArrowUp = "StepUpArrowUp";
  8.    var upArrowDown = "StepUpArrowDown";
  9.    var upArrowOver = "StepUpArrowOver";
  10.    var upArrowDisabled = "StepUpArrowDisabled";
  11.    var downArrowUp = "StepDownArrowUp";
  12.    var downArrowDown = "StepDownArrowDown";
  13.    var downArrowOver = "StepDownArrowOver";
  14.    var downArrowDisabled = "StepDownArrowDisabled";
  15.    var skinIDUpArrow = 10;
  16.    var skinIDDownArrow = 11;
  17.    var skinIDInput = 9;
  18.    var initializing = true;
  19.    var __visible = true;
  20.    var __minimum = 0;
  21.    var __maximum = 10;
  22.    var __stepSize = 1;
  23.    var __value = 0;
  24.    var __nextValue = 0;
  25.    var __previousValue = 0;
  26.    var clipParameters = {minimum:1,maximum:1,stepSize:1,value:1,maxChars:1};
  27.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.controls.NumericStepper.prototype.clipParameters,mx.core.UIComponent.prototype.clipParameters);
  28.    function NumericStepper()
  29.    {
  30.       super();
  31.    }
  32.    function init()
  33.    {
  34.       super.init();
  35.       this.boundingBox_mc._visible = false;
  36.       this.boundingBox_mc._width = this.boundingBox_mc._height = 0;
  37.       this._visible = false;
  38.       this.tabEnabled = false;
  39.       this.tabChildren = true;
  40.    }
  41.    function setVisible(x, noEvent)
  42.    {
  43.       super.setVisible(x,noEvent);
  44.       if(this.initializing)
  45.       {
  46.          this.__visible = x;
  47.       }
  48.    }
  49.    function layoutControl()
  50.    {
  51.       this.nextButton_mc._x = this.__width - this.nextButton_mc.__width;
  52.       this.nextButton_mc._y = 0;
  53.       this.prevButton_mc._x = this.__width - this.prevButton_mc.__width;
  54.       this.prevButton_mc._y = this.__height - this.prevButton_mc.__height;
  55.       this.inputField.setSize(this.__width - this.nextButton_mc.__width,this.__height);
  56.       this.StepTrack_mc._width = Math.max(this.nextButton_mc.__width,this.prevButton_mc.__width);
  57.       this.StepTrack_mc._x = this.__width - this.StepTrack_mc._width;
  58.       this.StepTrack_mc._height = this.__height - (this.nextButton_mc._height + this.prevButton_mc._height);
  59.       this.StepTrack_mc._y = this.nextButton_mc.__height;
  60.    }
  61.    function createChildren()
  62.    {
  63.       super.createChildren();
  64.       this.addAsset("nextButton_mc",this.skinIDUpArrow);
  65.       this.addAsset("prevButton_mc",this.skinIDDownArrow);
  66.       this.addAsset("inputField",this.skinIDInput);
  67.       this.focusTextField = TextField(this.inputField.label);
  68.       this.createObject("StepTrack","StepTrack_mc",2);
  69.       this.size();
  70.    }
  71.    function draw()
  72.    {
  73.       this.prevButton_mc.enabled = this.enabled;
  74.       this.nextButton_mc.enabled = this.enabled;
  75.       this.inputField.enabled = this.enabled;
  76.       this.size();
  77.       this.initializing = false;
  78.       this.__set__visible(this.__visible);
  79.    }
  80.    function size()
  81.    {
  82.       var _loc2_ = this.calcMinHeight();
  83.       var _loc3_ = this.calcMinWidth();
  84.       if(this.__height < _loc2_)
  85.       {
  86.          this.setSize(this.__width,_loc2_);
  87.       }
  88.       if(this.__width < _loc3_)
  89.       {
  90.          this.setSize(_loc3_,this.__height);
  91.       }
  92.       this.layoutControl();
  93.    }
  94.    function calcMinHeight()
  95.    {
  96.       return 22;
  97.    }
  98.    function calcMinWidth()
  99.    {
  100.       return 40;
  101.    }
  102.    function addAsset(id, skinID)
  103.    {
  104.       var _loc2_ = new Object();
  105.       _loc2_.styleName = this;
  106.       if(skinID == 10)
  107.       {
  108.          _loc2_.falseUpSkin = this.upArrowUp;
  109.          _loc2_.falseOverSkin = this.upArrowOver;
  110.          _loc2_.falseDownSkin = this.upArrowDown;
  111.          _loc2_.falseDisabledSkin = this.upArrowDisabled;
  112.          this.createClassObject(mx.controls.SimpleButton,id,skinID,_loc2_);
  113.          var _loc4_ = this.nextButton_mc;
  114.          _loc4_.tabEnabled = false;
  115.          _loc4_.styleName = this;
  116.          _loc4_._x = this.__width - _loc4_.__width;
  117.          _loc4_._y = 0;
  118.          _loc4_.owner = this;
  119.          _loc4_.autoRepeat = true;
  120.          _loc4_.clickHandler = function()
  121.          {
  122.             Selection.setSelection(0,0);
  123.          };
  124.          _loc4_.buttonDownHandler = function()
  125.          {
  126.             this.owner.buttonPress(this);
  127.          };
  128.       }
  129.       else if(skinID == 11)
  130.       {
  131.          _loc2_.falseUpSkin = this.downArrowUp;
  132.          _loc2_.falseOverSkin = this.downArrowOver;
  133.          _loc2_.falseDownSkin = this.downArrowDown;
  134.          _loc2_.falseDisabledSkin = this.downArrowDisabled;
  135.          this.createClassObject(mx.controls.SimpleButton,id,skinID,_loc2_);
  136.          var _loc3_ = this.prevButton_mc;
  137.          _loc3_.tabEnabled = false;
  138.          _loc3_.styleName = this;
  139.          _loc3_._x = this.__width - _loc3_.__width;
  140.          _loc3_._y = this.__height - _loc3_.__height;
  141.          _loc3_.owner = this;
  142.          _loc3_.autoRepeat = true;
  143.          _loc3_.clickHandler = function()
  144.          {
  145.             Selection.setSelection(0,0);
  146.          };
  147.          _loc3_.buttonDownHandler = function()
  148.          {
  149.             this.owner.buttonPress(this);
  150.          };
  151.       }
  152.       else if(skinID == 9)
  153.       {
  154.          this.createClassObject(mx.controls.TextInput,id,skinID);
  155.          var _loc5_ = this.inputField;
  156.          _loc5_.styleName = this;
  157.          _loc5_.setSize(this.__width - this.nextButton_mc.__width,this.__height);
  158.          _loc5_.restrict = "0-9\\-\\.\\,";
  159.          _loc5_.maxChars = this.__maxChars;
  160.          _loc5_.text = this.value;
  161.          _loc5_.onSetFocus = function()
  162.          {
  163.             this._parent.onSetFocus();
  164.          };
  165.          _loc5_.onKillFocus = function()
  166.          {
  167.             this._parent.onKillFocus();
  168.          };
  169.          _loc5_.drawFocus = function(b)
  170.          {
  171.             this._parent.drawFocus(b);
  172.          };
  173.          _loc5_.onKeyDown = function()
  174.          {
  175.             this._parent.onFieldKeyDown();
  176.          };
  177.       }
  178.    }
  179.    function setFocus()
  180.    {
  181.       Selection.setFocus(this.inputField);
  182.    }
  183.    function onKillFocus()
  184.    {
  185.       mx.managers.SystemManager.form.focusManager.defaultPushButtonEnabled = true;
  186.       super.onKillFocus();
  187.       Key.removeListener(this.inputField);
  188.       if(Number(this.inputField.text) != this.__get__value())
  189.       {
  190.          var _loc3_ = this.checkValidValue(Number(this.inputField.text));
  191.          this.inputField.text = _loc3_;
  192.          this.__set__value(_loc3_);
  193.          this.dispatchEvent({type:"change"});
  194.       }
  195.    }
  196.    function onSetFocus()
  197.    {
  198.       super.onSetFocus();
  199.       Key.addListener(this.inputField);
  200.       mx.managers.SystemManager.form.focusManager.defaultPushButtonEnabled = false;
  201.    }
  202.    function onFieldKeyDown()
  203.    {
  204.       var _loc2_ = this.__get__value();
  205.       switch(Key.getCode())
  206.       {
  207.          case 40:
  208.             var _loc3_ = this.__get__value() - this.__get__stepSize();
  209.             this.__set__value(_loc3_);
  210.             if(_loc2_ != this.__get__value())
  211.             {
  212.                this.dispatchEvent({type:"change"});
  213.             }
  214.             break;
  215.          case 38:
  216.             _loc3_ = this.__get__stepSize() + this.__get__value();
  217.             this.__set__value(_loc3_);
  218.             if(_loc2_ != this.__get__value())
  219.             {
  220.                this.dispatchEvent({type:"change"});
  221.             }
  222.             break;
  223.          case 36:
  224.             this.inputField.text = this.minimum;
  225.             this.__set__value(this.minimum);
  226.             if(_loc2_ != this.__get__value())
  227.             {
  228.                this.dispatchEvent({type:"change"});
  229.             }
  230.             break;
  231.          case 35:
  232.             this.inputField.text = this.maximum;
  233.             this.__set__value(this.maximum);
  234.             if(_loc2_ != this.__get__value())
  235.             {
  236.                this.dispatchEvent({type:"change"});
  237.             }
  238.             break;
  239.          case 13:
  240.             this.__set__value(Number(this.inputField.text));
  241.             if(_loc2_ != this.__get__value())
  242.             {
  243.                this.dispatchEvent({type:"change"});
  244.                break;
  245.             }
  246.       }
  247.    }
  248.    function get nextValue()
  249.    {
  250.       if(this.checkRange(this.__get__value() + this.__get__stepSize()))
  251.       {
  252.          this.__nextValue = this.__get__value() + this.__get__stepSize();
  253.          return this.__nextValue;
  254.       }
  255.    }
  256.    function get previousValue()
  257.    {
  258.       if(this.checkRange(this.__value - this.__get__stepSize()))
  259.       {
  260.          this.__previousValue = this.__get__value() - this.__get__stepSize();
  261.          return this.__previousValue;
  262.       }
  263.    }
  264.    function set maxChars(num)
  265.    {
  266.       this.__maxChars = num;
  267.       this.inputField.maxChars = this.__maxChars;
  268.    }
  269.    function get maxChars()
  270.    {
  271.       return this.__maxChars;
  272.    }
  273.    function get value()
  274.    {
  275.       return this.__value;
  276.    }
  277.    function set value(v)
  278.    {
  279.       var _loc2_ = this.checkValidValue(v);
  280.       if(_loc2_ == this.__value)
  281.       {
  282.          return undefined;
  283.       }
  284.       this.inputField.text = this.__value = _loc2_;
  285.    }
  286.    function get minimum()
  287.    {
  288.       return this.__minimum;
  289.    }
  290.    function set minimum(v)
  291.    {
  292.       this.__minimum = v;
  293.    }
  294.    function get maximum()
  295.    {
  296.       return this.__maximum;
  297.    }
  298.    function set maximum(v)
  299.    {
  300.       this.__maximum = v;
  301.    }
  302.    function get stepSize()
  303.    {
  304.       return this.__stepSize;
  305.    }
  306.    function set stepSize(v)
  307.    {
  308.       this.__stepSize = v;
  309.    }
  310.    function onFocus()
  311.    {
  312.    }
  313.    function buttonPress(button)
  314.    {
  315.       var _loc2_ = this.__get__value();
  316.       if(button._name == "nextButton_mc")
  317.       {
  318.          this.value += this.stepSize;
  319.       }
  320.       else
  321.       {
  322.          this.value -= this.stepSize;
  323.       }
  324.       if(_loc2_ != this.__get__value())
  325.       {
  326.          this.dispatchEvent({type:"change"});
  327.          Selection.setSelection(0,0);
  328.       }
  329.    }
  330.    function checkRange(v)
  331.    {
  332.       return v >= this.__get__minimum() and v <= this.__get__maximum();
  333.    }
  334.    function checkValidValue(val)
  335.    {
  336.       var _loc7_ = val / this.__get__stepSize();
  337.       var _loc9_ = Math.floor(_loc7_);
  338.       var _loc2_ = this.__get__stepSize();
  339.       var _loc6_ = this.__get__minimum();
  340.       var _loc5_ = this.__get__maximum();
  341.       if(val > _loc6_ and val < _loc5_)
  342.       {
  343.          if(_loc7_ - _loc9_ == 0)
  344.          {
  345.             return val;
  346.          }
  347.          var _loc8_ = Math.floor(val / _loc2_);
  348.          var _loc4_ = _loc8_ * _loc2_;
  349.          if(val - _loc4_ >= _loc2_ / 2 && _loc5_ >= _loc4_ + _loc2_ && _loc6_ <= _loc4_ - _loc2_ || val + _loc2_ == _loc5_ && _loc5_ - _loc4_ - _loc2_ > 1e-14)
  350.          {
  351.             _loc4_ += _loc2_;
  352.          }
  353.          return _loc4_;
  354.       }
  355.       if(val >= _loc5_)
  356.       {
  357.          return _loc5_;
  358.       }
  359.       return _loc6_;
  360.    }
  361.    function onLabelChanged(o)
  362.    {
  363.       var _loc2_ = this.checkValidValue(Number(o.__get__text()));
  364.       o.__set__text(_loc2_);
  365.       this.__set__value(_loc2_);
  366.    }
  367.    function get tabIndex()
  368.    {
  369.       return this.inputField.tabIndex;
  370.    }
  371.    function set tabIndex(w)
  372.    {
  373.       this.inputField.tabIndex = w;
  374.    }
  375. }
  376.